﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="/Themes/Styles/style.css" rel="stylesheet" type="text/css" />
    <link href="/Themes/Scripts/artDialog/skins/black.css" rel="stylesheet" type="text/css" />

    <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/JValidator.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/artDialog.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/iframeTools.source.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/common.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/Jutil.js" type="text/javascript"></script>
    <script type="text/javascript">
        var testFlag = false;//测试是否成功
        $(function () {
            $("#AtatusType").change(function () {
                $("#LoginName,#Password").removeAttr("disabled");
                if (this.value == "2") {//sql验证
                    $("#LoginName,#Password").attr("disabled", "disabled");
                }
            });
            LoginTest();
        });
        //登录
        function Login() {
            if (!testFlag) {
                ShowWarningMsg("您的测试没有通过！");
                return false;
            }
            if ($("#AtatusType").val() == "1" && CheckDataValid('#form1'))
                return true;
            Login();
            return false;
        }

        //测试登录
        function Login() {
            testFlag = false;
            var parm = 'action=Login&ServerName=' + escape($("#ServerName").val()) + '&AtatusType=' + escape($("#AtatusType").val()) + '&LoginName=' + escape($("#LoginName").val());
            parm += '&Password=' + escape($("#Password").val()) + '&db=' + escape($("#Password").val());
            Loading(true);
            Ajax('/Ajax/Common_Ajax.ashx', parm, function (rs) {
                if (rs == "0" || rs == "") {
                    ShowWarningMsg("登录失败，请检查用户名和密码！");
                    return false;
                }
                window.parent.location.href = "/Frame/MainForm.aspx?db=" + $('#sel_DB').val();
                OpenClose();
            });
            Loading(false);
        }

        //测试登录
        function LoginTest() {
            testFlag = false;
            //*****************使用cookie******************
            var dbs = Jutil.getCookie("DB_LIST");//读取cookie
            if (dbs != null && dbs.length > 0) {
                LoadDb(dbs);
                testFlag = true;
                return;
            }
            //*********************************************
            var parm = 'action=DBTest&ServerName=' + escape($("#ServerName").val()) + '&AtatusType=' + escape($("#AtatusType").val()) + '&LoginName=' + escape($("#LoginName").val());
            parm += '&Password=' + escape($("#Password").val());
            Loading(true);
            Ajax('/Ajax/Common_Ajax.ashx', parm, function (rs) {
                if (rs == "0" || rs == "") {
                    ShowWarningMsg("登录测试失败，请检查用户名和密码！");
                    return false;
                }
                Jutil.setCookie("DB_LIST", rs)
                LoadDb(rs);
            });
            Loading(false);
        }
        //加载数据库
        function LoadDb(dbList) {
            if (dbList == null || dbList.length == 0)
                return;

            testFlag = true;
            var arr = dbList.split('|');
            $("#sel_DB").html("");
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] == "") continue;
                $("#sel_DB").append("<option value='" + arr[i] + "'>" + arr[i] + "</option>");
            }
        }
    </script>
</head>
<body>
    <form id="form1">
        <div style="width: 500px; height: 400px;">
            <table border="0" cellpadding="0" cellspacing="0" class="frm">
                <tr>
                    <th>
                        服务器名称（S）：
                    </th>
                    <td>
                        <input id="ServerName" type="text" class="txt" value=".\SQLEXPRESS" style="width: 250px" />
                    </td>
                </tr>
                <tr>
                    <th>
                        身份验证（A）：
                    </th>
                    <td>
                        <select id="AtatusType" class="select" style="width: 256px">
                            <option value="1">SQL Server身份验证</option>
                            <option value="2" selected="selected">Windows 身份验证</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>
                        登录名（L）：
                    </th>
                    <td>
                        <input id="LoginName" type="text" class="txt" value="sa" datacol="yes" disabled="disabled"
                               err="登录名" checkexpession="NotNull" style="width: 250px" />
                    </td>
                </tr>
                <tr>
                    <th>
                        密码（P）：
                    </th>
                    <td>
                        <input id="Password" type="text" class="txt" style="width: 250px" value="123456" datacol="yes" disabled="disabled"
                               err="密码" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <th>
                        数据库（D）：
                    </th>
                    <td>
                        <select id="sel_DB" class="select" style="width: 256px"></select>
                    </td>
                </tr>
                <tr>
                    <th></th>
                    <td>
                        <label>
                            <input type="checkbox" checked="checked" />
                            记住密码
                        </label>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="aui_buttons" style="margin-right: 190px;">
                            <button id="btnTest" type="button" class="aui_state_highlight" onclick="LoginTest();">测 试</button>
                            <button id="btnLogin" type="submit" name="btnLogin" class="aui_state_highlight" onclick="return Login();">链 接</button>
                            <button onclick="OpenClose();">关 闭</button>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
